package com.central.utils

import java.security.MessageDigest

object StringUtils {

  def convertToMD5(source: String): String = {
    if (source == null || source.length == 0) {
      return ""
    }
    else {

      try {
        val btInput: Array[Byte] = source.getBytes("UTF-8")
        val digest: MessageDigest = MessageDigest.getInstance("MD5")
        digest.update(btInput)
        val md5: Array[Byte] = digest.digest()
        val buffer = new StringBuffer

        for (i <- 0 to md5.length - 1) {
          var result = md5(i) & 255
          if (result < 16) {
            buffer.append("0")
          }

          buffer.append(Integer.toHexString(result))
        }
        return buffer.toString
      } catch {
        case e =>
          return ""
      }
    }
  }

  def isEmpty(source: String): Boolean = {
    if (source == null || source.length == 0) {
      return true
    } else
      return false
  }
}
